package cre.sample.test.lock;

public class UnsafeSequence {

	private int value;

	public int getValue() {
		return value++;
	}

	public static void main(String[] args) throws InterruptedException {
		
		final UnsafeSequence us = new UnsafeSequence();
		Thread th1 = new Thread("th1") {
			@Override
			public void run() {
				System.out.println( us.getValue()+" "+super.getName());
			}
		};

		Thread th2 = new Thread("th2") {
			@Override
			public void run() {
				System.out.println(us.getValue()+" "+super.getName());
			}
		};

		th1.start();
		/**
		 * 如果不執行Thread.sleep(1000);
		 * 偶尔結果为：
		 * 0 th2
		 * 0 th1
		 * 如果执行Thread.sleep(1000);
		 * 结果为：
		 * 0 th1
		 * 1 th2
		 */
		//Thread.sleep(1000);
		th2.start();
	}
}